package anx;

import static org.junit.Assert.assertFalse;
import anx.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Tests that Runner always is facing in a proper heading.
 * @author Anthony Xu
 *
 */
public class TestRunnerCorrectHeading extends RobotTestBed {
  /** True if Runner's heading is between 20-70 degrees from vertical and horizontal. */
  boolean correctHeading = true;
  
  /**
   * Specifies that SittingDuck and Runner in the test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,anx.Runner";
  }
  
  /**
   * This test runs for 1 round.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 1;
  }
  
  /**
   * After each turn, check to see if the heading is correct. If not, change boolean to false.
   * @param event everytime the turn ends
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    if ((robot.getBodyHeading() <= 20) || (robot.getBodyHeading() >= 70)) {
      correctHeading = false;
    }
  }
  
  
  /**
   * After the battle, check to see if there was a time where the heading was incorrect.
   * @param event when the battle is finished
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertFalse("Correct Heading", correctHeading);    
  }

}
